package com.lc.servlet;

import com.lc.service.UserinfoService;
import com.lc.service.impl.UserinfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @description:
 * @author: ManolinCoder
 * @time: 2021/8/20
 */
@WebServlet("/sign")
public class signServlet extends HttpServlet {
    UserinfoService userinfoService = new UserinfoServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取ajax传过来的uname
        String uname = req.getParameter("uname");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        if (userinfoService.getUserinfoByUname(uname) == null){
            writer.print("用户名合法!");
        }else if (uname==""){
            writer.print("用户名为空!");
        }else {
            writer.print("用户名已被注册!");
        }
    }
}
